﻿/*
    File name:          Scale
    File type:          Class
    Author:             Sune Krog-Meyer 09888
    Creation date:      03-04-2011
    Description:        Contains weightmeasuringfunktions for the robot.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using i4pro_gruppe_d.ControllerCommunication;
using i4pro_gruppe_d.RobotCommunication;
using i4pro_gruppe_d.SimulatorAdaptor;

namespace i4pro_gruppe_d.Hardware
{
    public class Scale
    {
        private readonly IControllerCommunication _scale;
        private readonly double divisionFactor = 1.0736, zero = 334.47;

        /// <summary>
        /// Classconstructor
        /// </summary>
        /// <param name="physical"> True if robot, false if simulator </param>
        public Scale(bool physical)
        {
            if(physical)
            {
                _scale = new ConcreteDLLAdaptor();
            }
            else
            {
                _scale = new ConcreteSimulatorAdaptor();
            }
        }
        
        /// <summary>
        /// Returns the measured weight
        /// </summary>
        /// <returns> weight in gram without </returns>
        public int MeasureWeight()
        {
            return (int)ConvertToWeight();
        }

        /// <summary>
        /// Convertes the value receive from the ADC to gram
        /// </summary>
        /// <returns> doublevalue of weightconvertion </returns>
        private double ConvertToWeight()
        {
            double tempValue = _scale.measureWeight();
            return ((tempValue - zero) / divisionFactor);
        }
    }
}
